import { stringify } from 'qs';
import request from '@/utils/request';

export async function queryPorduct(params) {
  return request(`/api/products?${stringify(params)}`);
}

export async function queryClass(params) {
  return request(`/api/products/class?${stringify(params)}`);
}

export async function queryModel(params) {
  return request(`/api/products/model?${stringify(params)}`);
}

export async function queryDecoder() {
  return request(`/api/products/decoder`);
}

export async function queryEncoder() {
  return request(`/api/products/encoder`);
}

export async function queryDetail(params) {
  return request(`/api/product/${params}`);
}

export async function add(params) {
  return request('/api/product', {
    method: 'POST',
    body: {
      ...params,
    },
  });
}

export async function del(params) {
  return request(`/api/product/${params}`, {
    method: 'DELETE',
  });
}

export async function edit(params) {
  return request(`/api/product/`, {
    method: 'PUT',
    body: {
      ...params,
    },
  });
}

export async function publish(params) {
  return request(`/api/product/publish`, {
    method: 'PUT',
    body: {
      ...params,
    },
  });
}

export async function addTopic(params) {
  return request('/api/product/topic', {
    method: 'POST',
    body: {
      ...params,
    },
  });
}

export async function queryTopics(params) {
  return request(`/api/product/${params}/topics`);
}

export async function delTopic(params) {
  return request(`/api/product/topic/${params}`, {
    method: 'DELETE',
  });
}
export async function qryStandardFunction(params) {
  return request(`/api/product/${params}/standardfunctions`);
}

export async function qryCustomFunction(params) {
  return request(`/api/product/${params}/customfunctions`);
}
export async function addProp(params) {
  return request('/api/product/prop', {
    method: 'POST',
    body: {
      ...params,
    },
  });
}
export async function editProp(params) {
  return request(`/api/product/prop`, {
    method: 'PUT',
    body: {
      ...params,
    },
  });
}
export async function delProp(params) {
  return request(`/api/product/prop/${params}`, {
    method: 'DELETE',
  });
}

export async function queryProp(params) {
  return request(`/api/product/prop/${params}`);
}

export async function qryStandardProp(params) {
  return request(`/api/product/${params}/standardprops`);
}

export async function qryCustomProp(params) {
  return request(`/api/product/customprops?${stringify(params)}`);
}

export async function qryProductProps(params) {
  return request(`/api/product/${params}/props`);
}

export async function qryProtocolInfo(params) {
  return request(`/api/product/${params}/protocol`);
}

export async function editProtocol(params) {
  return request(`/api/product/protocol`, {
    method: 'PUT',
    body: {
      ...params,
    },
  });
}
export async function qryTcpMainProtocol(params) {
  return request(`/api/protocol/${params}/tcp/mainrules`);
}
export async function qryTcpChildProtocol(params) {
  return request(`/api/protocol/${params}/tcp/childrules`);
}
export async function qryRuleType() {
  return request(`/api/protocol/tcp/types`);
}
export async function addTcpProtocol(params) {
  return request('/api/protocol/tcp', {
    method: 'POST',
    body: {
      ...params,
    },
  });
}
export async function delTcpProtocol(params) {
  return request(`/api/protocol/tcp/${params}`, {
    method: 'DELETE',
  });
}
export async function qryTcpDetailInfo(params) {
  return request(`/api/protocol/tcp/${params}`);
}
export async function editTcpProtocol(params) {
  return request('/api/protocol/tcp', {
    method: 'PUT',
    body: {
      ...params,
    },
  });
}
export async function clearTcpRule(params) {
  return request(`/api/protocol/${params}/tcp/clear`, {
    method: 'DELETE',
  });
}
export async function qryMqttProtocol(params) {
  return request(`/api/protocol/mqtt?${stringify(params)}`);
}
export async function addOrUpdateMqttProtocol(params) {
  return request('/api/protocol/mqtt', {
    method: 'POST',
    body: {
      ...params,
    },
  });
}
export async function qryProductService(params) {
  return request(`/api/product/services?${stringify(params)}`);
}

export async function qryProtocolField(params) {
  return request(`/api/protocol/${params}/fields`);
}

export async function addService(params) {
  return request('/api/product/services', {
    method: 'POST',
    body: {
      ...params,
    },
  });
}
export async function qryServiceById(params) {
  return request(`/api/product/services/${params}`);
}
export async function editService(params) {
  return request('/api/product/services', {
    method: 'PUT',
    body: {
      ...params,
    },
  });
}

export async function delService(params) {
  return request(`/api/product/services/${params}`, {
    method: 'DELETE',
  });
}
